﻿Imports System.Data.SqlClient
Imports UTNComputers.clsConfiguraciones
Public Class daoConfiguraciones
    'Funcion para Traer las configuraciones'
    Public Function TraeConfiguraciones() As clsConfiguraciones
        Dim Cn As New SqlClient.SqlConnection
        Dim Cm As New SqlClient.SqlCommand
        Dim Dr As SqlClient.SqlDataReader
        Dim Configuracion As New clsConfiguraciones()

        Try
            Cn.ConnectionString = My.Resources.Conexion
            Cn.Open()
            Cm.CommandType = CommandType.StoredProcedure
            Cm.CommandText = "SP_TRAER_CONFIGURACIONES"


            Cm.Connection = Cn
            Dr = Cm.ExecuteReader
            If Dr.HasRows = True Then
                While Dr.Read
                    Configuracion.Cod_Suc = Dr.GetInt32(0)
                    Configuracion.Nom_Suc = Dr.GetString(1).Trim.ToUpper
                    Configuracion.Ganancia = Dr.GetDecimal(2)
                    Configuracion.Descuent_Empresas = Dr.GetDecimal(3)
                    Configuracion.Interes_Servicio_Express = Dr.GetDecimal(4)
                End While
                Dr.Close()
                Cn.Close()
            End If
            Return Configuracion
        Catch ex As Exception
            Throw New Exception(ex.Message)
        Finally
            Cn.Dispose()
            Cm.Dispose()
        End Try
    End Function

    '---------------------------------------------------------------------
    ' Constructor de la Clase
    '---------------------------------------------------------------------
    Public Sub New()

        MyBase.New()

    End Sub

    '---------------------------------------------------------------------
    ' Destructor de la Clase
    '---------------------------------------------------------------------
    Public Sub Dispose()

        MyBase.Finalize()

    End Sub

End Class
